package com.hg.chapter84.controller;

import com.hg.chapter84.entity.Worker;
import com.hg.chapter84.service.WorkerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class WorkerController {

    @Autowired
    private WorkerService workerService;

    @PostMapping("/worker")
    public Worker addWorker(@RequestBody Worker worker){
        return workerService.save(worker);
    }

    @GetMapping("/worker/{id}")
    public Worker getWorker(@PathVariable Integer id){
        Worker worker=new Worker();
        worker.setId((long)id);
        return workerService.findOne(worker);
    }

    @DeleteMapping("/worker/{id}")
    public void delWorker(@PathVariable Integer id){
        workerService.remove((long)id);
    }
}
